package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.common.Result;
import org.example.entity.Audit;
import org.example.entity.Choose;
import org.example.service.ChooseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/select")
public class ChooseController {
    @Resource
    ChooseService chooseService;
    @GetMapping("/teachers")
    public Result getAllTeachers(){
        return chooseService.getAllTeachers();
    }
    //选择教师
    @PostMapping("/selectTeacher")
    public Result selectTeacher (@RequestBody List<Integer> list){
        Integer teacherId= list.get(0);
        Integer userId= list.get(1);
        chooseService.addSelection(teacherId,userId);
//        Map<String, Integer> responseData = new HashMap<>();
//        responseData.put("teacherId", teacherId);
        return Result.success();
    }
    @GetMapping("/selectedTeacher")
    public Result getSelectedTeacher(@RequestParam Integer userId){
        return chooseService.getSelectedTeacher(userId);
    }
    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Choose> chooseList = chooseService.list(new QueryWrapper<Choose>().orderByDesc("id"));  //select * from user order by id desc
        return Result.success(chooseList);
    }

}
